home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Interactive Web Graphics with Shout 3D
/
Interactive Web Graphics With Shout 3D.iso
/
pc
/
Code
/
Chapter Code.exe
/
Chapter10
/
TargetViewpoint1TestPanel.java
< prev
next >
Wrap
Text File
|
2000-09-08
|
2KB
|
98 lines
package applets;
import shout3d.*;
import shout3d.core.*;
import shout3d.math.*;
import custom_nodes.*;
public class TargetViewpoint1TestPanel extends Shout3DPanel implements DeviceObserver {
int pixelStartX;
int pixelStartY;
int pixelEndX;
int pixelEndY;
TargetViewpoint1 cam;
public TargetViewpoint1TestPanel(Shout3DApplet applet){
super(applet);
}
public void customInitialize() {
addDeviceObserver(this,"MouseInput", null);
cam = (TargetViewpoint1) getCurrentBindableNode("Viewpoint");
}
protected void finalize() {
removeDeviceObserver(this,"MouseInput");
}
public boolean onDeviceInput(DeviceInput di, Object userData) {
MouseInput mi = (MouseInput) di;
switch (mi.which){
case MouseInput.DOWN:
pixelStartX = mi.x;
pixelStartY = mi.y;
return true;
case MouseInput.DRAG:
//if left button used
if(mi.button == 0) {
pixelEndX = mi.x;
pixelEndY = mi.y;
int dragDistanceX = pixelEndX - pixelStartX;
int dragDistanceY = pixelEndY - pixelStartY;
//convert drag to rotation
//at 70 pixels per radian (57.3 degrees)
float headingDelta = dragDistanceX/70f;
float pitchDelta = dragDistanceY/70f;
//compute new heading and pitch
float temp = cam.heading.getValue() - headingDelta;
cam.heading.setValue(temp);
temp = cam.pitch.getValue() - pitchDelta;
cam.pitch.setValue(temp);
pixelStartY = pixelEndY;
pixelStartX = pixelEndX;
return true;
}//end of 0 if
//if right button used
if(mi.button == 1) {
pixelEndY = mi.y;
int dragDistanceY = pixelEndY - pixelStartY;
float distanceDelta = dragDistanceY/150f;
float temp = cam.distance.getValue() + distanceDelta;
cam.distance.setValue(temp);
pixelStartY = pixelEndY;
return true;
}//end of 1 if
}//end of switch
return false;
}
}//end of class